package zhishu.iceyyy.com.bxq_2500.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import zhishu.iceyyy.com.bxq_2500.R;
import zhishu.iceyyy.com.bxq_2500.adapter.Soucang_Adapter;
import zhishu.iceyyy.com.bxq_2500.adapter.Sousuo_Adapter;
import zhishu.iceyyy.com.bxq_2500.api.API;
import zhishu.iceyyy.com.bxq_2500.api.Okhttp;
import zhishu.iceyyy.com.bxq_2500.bean.Serach;
import zhishu.iceyyy.com.bxq_2500.utils.JSONUtils;

public class ShouCangActivity extends AppCompatActivity {

    @BindView(R.id.img_back)
    RelativeLayout imgBack;



    @BindView(R.id.activity_seetting)
    LinearLayout activitySeetting;
    @BindView(R.id.lv_lv)
    ListView lvLv;
    Soucang_Adapter sousuo_adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shoucang);
        ButterKnife.bind(this);

        sousuo_adapter = new Soucang_Adapter(this);
        lvLv.setAdapter(sousuo_adapter);
        lvLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Serach.DataBean.MovicesBean item = (Serach.DataBean.MovicesBean) sousuo_adapter.getItem(position);
                startActivity(new Intent(ShouCangActivity.this, Work_Activity.class).putExtra("value", "" + item.getVod_id()));

            }
        });
        shoucang();
    }

    @OnClick({R.id.img_back })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;

        }
    }
    public  void  shoucang(){
        API.search( "", "0", new Okhttp.Objectcallback() {
            @Override
            public void onsuccess(String st) {
                Log.e("88888", "xx" + st);
//                        startActivity(new Intent(this, xx.class));
                Serach sousuo = JSONUtils.parseJSON(st, Serach.class);
                if (sousuo.getCode().equals("200")) {
                    if ((sousuo.getData().getMovices() != null && sousuo.getData().getMovices().size() > 0)) {
                        List<Serach.DataBean.MovicesBean> data = sousuo.getData().getMovices();
                        sousuo_adapter.addItem(data);
                    } else {
                        Toast.makeText(ShouCangActivity.this, "暂无搜索结果！", Toast.LENGTH_SHORT).show();
                    }

                } else {
                    Toast.makeText(ShouCangActivity.this, "" + sousuo.getMessage(), Toast.LENGTH_SHORT).show();
                }

            }

            @Override
            public void onFalia(int code, String errst) {
                Log.e("88888", "xx" + errst);
                Toast.makeText(ShouCangActivity.this, "网络错误！" + errst, Toast.LENGTH_SHORT).show();
            }
        });

    }
}
